<template>
	<view>
		<view class="u-flex-col u-col-center">
			<image src="../../static/logo.jpg" class="logo"></image>
			<view class="m-t-10">MagicEletronicKey</view>
			<view style="width: 500rpx;margin-top: 30vh;">
				<u-button type="primary" @click="login">登录</u-button>
			</view>
		</view>
		
	</view>
</template>

<script>
	const userCloud = uniCloud.importObject('user');
	import {
		setUser
	} from "../../utils/storage";
	export default {
		data() {
			return {
				
			};
		},
		methods:{
			login(){
				uni.login({
					provider:"weixin",
					success: async (res) => {
						if(res.code){
							let loginRes = await userCloud.login(res.code);
							if(loginRes.errCode == 0){
								const openid = loginRes.data.openid;
								// const session_key = loginRes.data.session_key;
								setUser({
									openid
								})
								uni.navigateTo({
									url:"/pages/index/index"
								})
							}
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.logo{
	width: 200rpx;
	height: 200rpx;
	border-radius: 50%;
	margin-top: 15vh;
}
</style>
